/*******************************************************************************
 * Package: com.hngtrust.iir.third.controller
 * Type:    ChinaTrustRegistrationController
 * Date:    2021/10/14 10:26
 *
 * Copyright (c) 2021 HUANENG GUICHENG TRUST CORP.,LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hngtrust.iir.third.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.hngtrust.framework.bind.ResponseInfo;
import com.hngtrust.iir.third.controller.dto.BeneficiaryExportVO;
import com.hngtrust.iir.third.controller.dto.BeneficiaryVO;
import com.hngtrust.iir.third.controller.dto.CtrBeneficiaryDTO;
import com.hngtrust.iir.third.controller.dto.CtrBeneficiaryExportDTO;
import com.hngtrust.iir.third.service.BeneficiaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 调用中信登第三方接口（受益所有人）
 *
 * @author Yujiaqi
 * @date 2021/10/14 10:26
 */

@Slf4j
@RestController
@RequestMapping("/beneficiary")
@Api(tags = "调用中信登第三方接口（受益所有人）")
public class BeneficiaryController {
    
    @Autowired
    private BeneficiaryService beneficiaryService;
    
    @ApiOperation(value = "受益所有人查询", notes = "受益所有人查询")
    @PostMapping("/query-beneficiary")
    public ResponseInfo<List<CtrBeneficiaryDTO>> queryBeneficiary(
            @ApiParam("受益人请求参数") @Valid @RequestBody BeneficiaryVO beneficiaryVO) throws JsonProcessingException {
        log.info("BeneficiaryController.queryBeneficiary start...");
        return beneficiaryService.beneficiary(beneficiaryVO);
    }
    
    @ApiOperation(value = "更新中信登受益人数据", notes = "更新中信登受益人数据")
    @PostMapping("/update-beneficiary")
    public ResponseInfo<List<CtrBeneficiaryDTO>> updateBeneficiary(
            @ApiParam("受益人请求参数") @Valid @RequestBody BeneficiaryVO beneficiaryVO) throws JsonProcessingException {
        log.info("BeneficiaryController.updateBeneficiary start...");
        return beneficiaryService.updateBeneficiary(beneficiaryVO);
    }
    
    @ApiOperation(value = "受益人模板下载", notes = "受益人模板下载")
    @PostMapping("/template-download")
    public ResponseInfo templateDownload(HttpServletResponse response) throws IOException {
        log.info("BeneficiaryController.templateDownload start...");
        beneficiaryService.templateDownload(response);
        return new ResponseInfo();
    }
    
    @ApiOperation(value = "批量调用中债登数据", notes = "批量调用中债登数据")
    @PostMapping("/add-beneficiarys")
    public ResponseInfo<List<CtrBeneficiaryExportDTO>> addBeneficiarys(
            @ApiParam(value = "导入文件", type = "MultipartFile", required = true) @RequestParam() MultipartFile file)
            throws IOException {
        log.info("BeneficiaryController.addBeneficiarys start...");
        return beneficiaryService.addBeneficiarys(file);
    }
    
    @ApiOperation(value = "受益人数据导出", notes = "受益人数据导出")
    @PostMapping("/data-export")
    public void dataExport(
            @ApiParam("受益人请求参数") @Valid @RequestBody BeneficiaryExportVO beneficiaryExport,HttpServletResponse response)
            throws IOException {
        log.info("BeneficiaryController.dataExport start...");
        beneficiaryService.dataExport(beneficiaryExport,response);
    }
    
    
    
    
    
}
